package com.zp.base.admin.config;

import com.zp.base.admin.interceptor.MenuInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author ZhangPeng
 * @email zhangpeng98@aliyun.com
 * @create 2021-03-01 10:43
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Autowired
    MenuInterceptor menuInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(menuInterceptor)
                .addPathPatterns("/system/**", "/admin/menu/**", "/admin/role/**", "/admin/user/**", "/admin/database_bak/**")
                .excludePathPatterns("/system/logout", "/system/login");
    }

    @Value("${zp.upload.photo.path}")
    private String uploadPhotoPath;
    @Value("${zp.upload.default.path}")
    private String uploadDefaultPath;

    //资源访问映射器
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler(uploadDefaultPath + "**").addResourceLocations("file:" + uploadPhotoPath);
    }

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("/system/index");
    }
}
